package othello.players;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import othello.gui.IGui;

public class HumanPlayer extends AbstractPlayer implements MouseListener, MouseMotionListener {

    public HumanPlayer() {
        super("Human");
    }

    @Override
    public void beginTurn() {
        IGui.get().addListener(this);
    }

    @Override
    public void endTurn() {
        IGui.get().removeListener(this);
    }
    
    @Override
	public void endGame() {
	}

    @Override
    public void mouseClicked(MouseEvent e) {
        Point pt = IGui.get().getSquare(e.getPoint());
        if (pt != null) {
            board.placePiece(HumanPlayer.this, pt.y, pt.x);
        } else if (IGui.get().isPassButton(e.getPoint())) {
            board.pass(HumanPlayer.this);
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    	Point pt = IGui.get().getSquare(e.getPoint());
        if (pt != null && board.isValidMove(getColor(), pt.y, pt.x)) {
            IGui.get().showDropIndicator(getColor(), pt.y, pt.x);
        } else if (IGui.get().isPassButton(e.getPoint())) {
            // Special code meaning the Pass button should be highlighted.
            IGui.get().showDropIndicator(null, board.getRowCount(), -1);
        } else {
            IGui.get().showDropIndicator(null, -1, -1);
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mouseDragged(MouseEvent e) {
    }
}
